#include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};

vector<vector<int>> levelOrder(Node* root) {
    if(root == nullptr) return vector<vector<int>> {};
    vector<vector<int>> ans;
    queue<Node*> Q;
    Q.push(root);
    while(!Q.empty()){
        int size = Q.size();
        vector<int> aa;
        for(int i=0;i<size;i++){
            Node* p = Q.front();
            Q.pop();
            aa.push_back(p->val);
            if(p->children.size() != 0){
                for(auto& child : p->children) Q.push(child);
            }
        }
        ans.push_back(aa);
    }
    return ans;
}